/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.sga.view.splash;

import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.netbeans.lib.awtextra.AbsoluteConstraints;
import org.netbeans.lib.awtextra.AbsoluteLayout;

/**
 *
 * @author Diogo
 */
public class Launcher extends JWindow {

    private AbsoluteLayout layout;
    private AbsoluteConstraints imageConstraints;
    private AbsoluteConstraints barConstraints;
    private ImageIcon imagem;
    private JLabel loader;
    private JProgressBar bar;
    private JLabel label;

    public Launcher() {
        this.layout = new AbsoluteLayout();
        this.imageConstraints = new AbsoluteConstraints(0, 0);
        this.barConstraints = new AbsoluteConstraints(10, 295);
        this.loader = new JLabel();
        this.imagem = new ImageIcon(this.getClass().getResource("splash.png"));
        this.loader.setIcon(imagem);
        this.bar = new JProgressBar();
        this.bar.setPreferredSize(new Dimension(350, 25));
        this.bar.setValue(5);
        this.label = new JLabel();
        this.label.setText("Carregando...");
        
        this.getContentPane().setLayout(layout);
        this.getContentPane().add(label,new AbsoluteConstraints(370, 300));
        this.getContentPane().add(bar, barConstraints);
        this.getContentPane().add(loader, imageConstraints);
        
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
        }
        SwingUtilities.updateComponentTreeUI(this);
        this.pack();
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        try {
            Thread.sleep(5000);
            this.bar.setValue(10);
            Thread.sleep(1000);
            this.bar.setValue(15);
            Thread.sleep(1000);
            this.bar.setValue(20);            
            this.dispose();
        } catch (Exception ex) {
            ex.printStackTrace();
            System.exit(ERROR);
        }
    }

    public static void main(String[] args) {
        new Launcher();
    }
}
